package com.hongyuan.sellcoach.ui.person.view_mode;

import android.app.Application;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.databinding.ObservableArrayList;
import androidx.databinding.ObservableField;
import androidx.databinding.ObservableList;
import com.hongyuan.mvvmhabitx.binding.command.BindingCommand;
import com.hongyuan.sellcoach.R;
import com.hongyuan.sellcoach.base.CustomViewModel;
import com.hongyuan.sellcoach.data.Constants;
import com.hongyuan.sellcoach.data.MyRepository;
import com.hongyuan.sellcoach.ui.course.activity.CourseListActivity;
import com.hongyuan.sellcoach.ui.course.beans.MyCourseBeans;
import com.hongyuan.sellcoach.ui.home.activity.EditTimeActivity;
import com.hongyuan.sellcoach.ui.person.activity.CoachImgActivity;
import com.hongyuan.sellcoach.ui.person.activity.CoachProfileActivity;
import com.hongyuan.sellcoach.ui.person.beans.CoachDeatilsBean;
import com.hongyuan.sellcoach.ui.person.beans.CoachIdleTimeBean;
import java.util.List;
import me.tatarka.bindingcollectionadapter2.BR;
import me.tatarka.bindingcollectionadapter2.ItemBinding;

public class CoachDetailsViewModel extends CustomViewModel<MyRepository> {

    public ObservableField<CoachDeatilsBean> entity = new ObservableField<>();
    public ObservableField<CoachIdleTimeBean> timeEntity = new ObservableField<>();

    public CoachDetailsViewModel(@NonNull Application application, MyRepository model) {
        super(application, model);
    }

    //给RecyclerView添加ObservableList
    public ObservableList<CoachLessonItemViewModel> lessonList = new ObservableArrayList<>();

    //给RecyclerView添加ItemBinding
    public ItemBinding<CoachLessonItemViewModel> lessonBinding = ItemBinding.of(BR.viewModel, R.layout.item_coach_lesson);

    //个人介绍
    public BindingCommand goProfile = new BindingCommand(() ->{
        Bundle bundle = new Bundle();
        bundle.putSerializable("profiles",entity.get());
        startActivity(CoachProfileActivity.class,bundle);
    });
    //更多课程
    public BindingCommand moreClass = new BindingCommand(() -> {
        startActivity(CourseListActivity.class);
    });

    //空闲时间
    public BindingCommand goIdleTime = new BindingCommand(() -> {
        startActivity(EditTimeActivity.class);
    });

    //教练风采
    public BindingCommand goCoachStyleImg = new BindingCommand(() -> {
        Bundle bundle = new Bundle();
        bundle.putString("title","教练风采");
        bundle.putString("coach_mid",userToken.getM_id());
        bundle.putString("photo_category_id","1");
        startActivity(CoachImgActivity.class,bundle);
    });
    //教练成功案例
    public BindingCommand goCoachSuccessImg = new BindingCommand(() -> {
        Bundle bundle = new Bundle();
        bundle.putString("title","成功案例");
        bundle.putString("coach_mid",userToken.getM_id());
        bundle.putString("photo_category_id","2");
        startActivity(CoachImgActivity.class,bundle);
    });
    //专业证书
    public BindingCommand goCoachCertificateImg = new BindingCommand(() -> {
        Bundle bundle = new Bundle();
        bundle.putString("title","专业证书");
        bundle.putString("coach_mid",userToken.getM_id());
        bundle.putString("photo_category_id","3");
        startActivity(CoachImgActivity.class,bundle);
    });

    @Override
    public void onResume() {
        super.onResume();

        requestData(Constants.GET_COACH_INDEX_INFO);
        requestData(Constants.GET_COACH_LAST_KONG_TIME);
    }

    @Override
    protected void returnData(int code, Object dataBean) {
        super.returnData(code, dataBean);


        if(code == Constants.GET_COACH_LAST_KONG_TIME){
            CoachIdleTimeBean idleTimeBean = (CoachIdleTimeBean)dataBean;
            timeEntity.set(idleTimeBean);
        }

        if(code == Constants.GET_COACH_INDEX_INFO){
            CoachDeatilsBean bean = (CoachDeatilsBean)dataBean;
            entity.set(bean);
        }

        if(code == Constants.GET_COURSE_PRIVITE_LIST){
            List<MyCourseBeans.ListBean> list = ((MyCourseBeans)dataBean).getList();
            if(list != null && list.size() > 0){
                for(int i = 0 ; i < list.size() ; i++){
                    CoachLessonItemViewModel itemViewModel = new CoachLessonItemViewModel(this,list.get(i),i,list.size() - 1);
                    lessonList.add(itemViewModel);
                }
            }
        }

    }
}
